package com.rainbow.security.entity

import com.fasterxml.jackson.annotation.JsonIgnore
import org.springframework.security.core.GrantedAuthority
import org.springframework.security.core.authority.SimpleGrantedAuthority
import org.springframework.security.core.userdetails.UserDetails

class User : UserDetails {

    var id: Long? = null

    var name: String? = null

    var phone: String? = null

    var telePhone: String? = null

    var address: String? = null

    var enabled: Boolean = true

    var roles: List<Role>? = null

    var userface: String? = null

    var remark: String? = null

    private var username: String = ""

    private var password: String = ""


    @JsonIgnore
    override fun getPassword(): String {
        return password
    }

    override fun getAuthorities(): MutableCollection<out GrantedAuthority> {

        val authorities = mutableListOf<GrantedAuthority>()
        for (role in roles!!) {
            authorities.add(SimpleGrantedAuthority(role.name))
        }
        return authorities
    }

    override fun isEnabled(): Boolean {
        return enabled
    }

    override fun getUsername(): String {
        return username;
    }

    @JsonIgnore
    override fun isAccountNonLocked(): Boolean {
        return true
    }

    @JsonIgnore
    override fun isAccountNonExpired(): Boolean {
        return true
    }

    override fun isCredentialsNonExpired(): Boolean {
        return true
    }
}